<template>
	<view class="container">
		<view class="top">
			<view class="title">{{title}}</view>
			<view class="time">发售时间 {{create_time}}</view>
		</view>
		<view class="box">
			<view class="num">
				<text class="data">{{all_people_num}}</text>
				<text>人已兑换</text>
			</view>
			<view class="list">
				<view class="item" v-for="item in list">
					<image :class="item.is_has?'img': 'img unactive'" :src="item.chip_icon" mode="aspectFill"></image>
					<view class="name">{{item.title}}</view>
				</view>
			</view>
			<view class="noData">
				<NoData v-if="!list.length"></NoData>
			</view>
		</view>
		<view class="bottom" v-if="list.length > 0">
			<view class="data">
				<text>{{num}}</text>
				<text>/{{all_num}}</text>
			</view>
			<view class="prize">奖励{{scoreAlias}}:{{give_score}}</view>
			<view class="btn" v-if="num < all_num" @click="goCollection">去收集</view>
			<view class="btn" v-else-if="is_exchange">已兑换</view>
			<view class="btn" v-else @click="submit">去兑换</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from "vuex"
	export default {
		data() {
			return {
				title:'',
				id:'',
				list:[],
				create_time:"",
				give_score:0,
				all_people_num:0,
				num:0,
				all_num:0,
				uuid:'',
				is_exchange:false
			}
		},
		computed: {
			...mapGetters(["userInfo"]),
		},
		watch: {
		},
		onLoad(e) {
			this.title = e.title
			this.id = e.id
			this.getDetail();
			
		},
		methods: {
			goCollection(){
				uni.navigateTo({
					url:'/pages/yifanshang/detail?uuid='+this.uuid
				})
			},
			getDetail(){
				this.$http('/activity/chipList/'+this.userInfo.uuid, 'GET', {
					activity_id: this.id,
				}).then(res => {
					this.list = res.data.list;
					this.create_time = res.data.created_at
					this.give_score = res.data.give_score
					this.all_people_num = res.data.all_people_num
					this.num = res.data.num
					this.all_num = res.data.all_num
					this.uuid = res.data.uuid
					this.is_exchange = res.data.is_exchange
				})
			},
			submit(){
				this.$http('/activity/chipExchange/'+this.userInfo.uuid, 'POST', {
					activity_id: this.id,
				}).then(res => {
					uni.showModal({
						content:res.data.msg
					})
					this.getDetail();
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #f3f3f3;
	}
	.top{
		padding: 35rpx 30rpx 20rpx 30rpx;
		font-family: alimama;
		.title{
			font-size: 36rpx;
		}
		.time{
			margin-top: 10rpx;
			font-size: 26rpx;
		}
	}
	.box{
		border-radius: 10rpx;
		width: 690rpx;
		background-color: #fff;
		margin: 0 auto;
		box-sizing: border-box;
		padding: 25rpx;
		.num{
			text{
				font-size: 26rpx;
			}
			text:nth-child(2){
				margin-left: 5rpx;
				color: #9e9e9e;
			}
			.data{
				font-family: alimama;
				font-size: 40rpx;
			}
		}
		.list{
			display: flex;
			flex-wrap: wrap;
			.noData{
				margin: 0 auto;
			}
			.item{
				margin-top: 10rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-right: 10rpx;
				width: 150rpx;
				.img{
					width: 100rpx;
					height: 150rpx;
				}
				.unactive{
					filter:brightness(10%);
					-webkit-filter: brightness(10%);
					-moz-filter: brightness(10%);
					-ms-filter: brightness(10%);
					-o-filter: brightness(10%);
				}
				.name{
					margin-top: 10rpx;
					font-size: 24rpx;
					color: #c9c9c9;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 1;
					-webkit-box-orient: vertical;
				}
			}
		}
	}
	
	.bottom{
		position: fixed;
		bottom: 0rpx;
		width: 750rpx;
		height: 140rpx;
		background-color: #000;
		padding: 20rpx;
		display: flex;
		align-items: center;
		.data{
			margin-left: 20rpx;
			width: 120rpx;
			color: yellow;
			font-family: alimama;
			text:nth-child(1){
				font-size: 42rpx;
			}
		}
		.prize{
			color: #fff;
			width: 350rpx;
		}
		.btn{
			border-radius: 5rpx;
			width: 200rpx;
			border: 2px solid #a0a0a0;
			color: white;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 15rpx 20rpx;
		}
	}
</style>
